home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap02
/
b02d010.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
4KB
|
86 lines
0, The program I'll create in this
2, demonstration is a bitmap browser, a tool you
4, can use to explore the bitmap files on
6, your system. To build a bitmap browser I'll
9, create a drive listbox object, a
13, directory listbox object, a file listbox
16, object, and an imagebox object. And I'll link
19, the four of them together with program
21, code. So, to get started I'll click the
24, drive listbox object on my toolbox and
27, go to the form and drag to create a drive
31, listbox object on the form. And I can
34, resize it with the selection handles. And
36, then I can click a directory listbox
38, object and drag to create it on my form.
42, And as you can see in both cases
44, information fills those so I can size them
47, correctly. And I'll use the file listbox
50, object to create a file listbox object on my form,
53, and it fills with file names. Now I'll
56, click the imagebox object and drag to
59, create an imagebox on my form. And just
62, like that I have the four elements of my
64, user interface. Now I'll click the file
67, listbox object and scroll down in the
70, properties window to the pattern property.
75, And I'll change that to *.bmp; *.wmf; and
83, *.ico with a semicolon inbetween each
86, entry so that Windows metafiles, and
89, bitmaps, and icons will appear when the
92, dialog box appears to list those files. Then
97, I'll go to the imagebox object and
100, scroll down to the stretch property and set
102, that to true so that large bitmap files
105, will shrink down to the image object and
110, tiny bitmap files will stretch out to
113, fill the entire imagebox object. That
115, will make it have a consistent look. And to
117, give it a bit of a 3-D appearance I'll
119, go up to the top of the properties
121, window and select border style and select
124, fixed single. And that'll give it a 3-D
126, look. Now let's continue to customize our
130, objects with program code. First, I'll
133, double-click the drive listbox object, and
137, in that event procedure I'll type
139, dir1.Path = Drive1. Drive. This code updates
151, the path property in the directory
154, listbox when the user selects a drive in the
157, drive listbox. Now I'll go to my
160, dropdown listbox and select the directory
162, listbox object. And in here I'll type file1.
171, path = dir1.Path. And that links the
179, file listbox to the directory listbox.
183, Finally, I'll click the file 1 object and
186, type the two important, really important
189, lines in my program code here. I'll type
195, SelectedFile, a variable, and I'll
199, assign that file 1.Path and the backslash
205, character and the File 1.File name
216, property. And then I'll use that variable in the
220, following statement.
225, Image1.Picture=LoadPicture, and then SelectedFile. What the
235, statement does is, with the
237, SelectedFile variable builds a complete Path name
241, using the file listbox object, a
244, backslash character, and then the file listbox
248, object. And then it loads it into the
252, picture property of the Image1 object with
255, the LoadPicture function, which uses the
260, selected file variable we created in
262, the program statement above. Okay, now
265, let's go ahead and run this program in the
267, programming environment and see what it
269, looks like. As you can see, the four
271, elements of our form appear and I can click
275, drive C, where I have some files loaded
278, and we can go to the LVB6 Chapter 2
281, folder. And in this folder we have a number
284, of file names that I can click. My
287, listbox is complete with scroll bars because
291, there's a long list. And as you can
293, see, each one of them appears as soon as I
295, single-click it. And that's my event
298, procedure at work.
300, END